function initRequest()
{
    var request = false;
    if(window.XMLHttpRequest) {         //FireFox
    request = new XMLHttpRequest();
    if (request.overrideMimeType) {
      request.overrideMimeType('text/xml');
    }
  }
  else if (window.ActiveXObject) {    //IE
    try {
      request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }
  if (!request) {
    window.alert("Create request error!");
    return false;
  }
  return request;
}

var http_request;
function send(sendUrl,data)
{
	var json;
  http_request = initRequest();
  sendUrl += "&random="+Math.random();   //在URL后添加这个，可以保证不被缓存
  //http_request.onreadystatechange = ajax_call_back;//指定请求返回时的回调函数

  //get
  //http_request.open("GET", sendUrl,true);
 // http_request.send("movie_id="+data);
  
  //post
   http_request.open("POST", sendUrl, false);
   http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   http_request.send("user_name="+data);
   var str=http_request.responseText;  
   json=JSON.parse(str); 
   
   return json;
 
}

function ajax_call_back()
{
    //readyState共有5中状态，0未初始化，1已初始化，2发送请求，3开始接收结果，4接收结果完毕。
    //status服务器响应状态码
  if (http_request.readyState == 4) {
    if (http_request.status == 200) {
       str = http_request.responseText;
     // return str
      alert("返回数据为："+str);
    }
    else if(http_request.status == 404){
      alert("请求资源不存在！");
    }
    else {
      alert("Ajax请求失败，错误状态为："+http_request.status);
    }
  }
}




function mycart(data)
{

var json=send("http://localhost:8080/movieManager/mycart.do?methodName=getMycart",data);
return json;
}

